<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="员工">
              <select-user-by-dep
                placeholder="请选择员工"
                v-model="queryParam.employeeId"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="团队">
              <select-team-input :query-type="'parent'" v-model="queryParam.teamId" :tdlx="3" :teamType="0" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="公司">
              <select-Company-input v-model="queryParam.companyId" placeholder="请选择公司" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="数据来源">
              <j-dict-select-tag
                type="list"
                v-model="queryParam.postDataSource"
                dictCode="post_data_source"
                placeholder="请选择数据来源"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" v-if="detail.isVirtual&&detail.isVirtual=='1'&&detail.isAddUser &&detail.isAddUser=='1'">新增</a-button>
      <!--<a-button type="primary" icon="download" @click="handleExportXls('公司员工岗位明细表')" :disabled="isDisabledAuth('erpCompanyEmployeePostDetail:export')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpCompanyEmployeePostDetail:import')">导入</a-button>
      </a-upload>
      -->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpCompanyEmployeePostDetail:delete')"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style="iconStyle"/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record" v-if="detail.isVirtual && detail.isVirtual == '1' && detail.isAddUser && detail.isAddUser == '1' && record.postDataSource =='post'">
          <a-button
            class="ruleButton"
            :ghost="true"
            type="primary"
            icon="edit"
            @click="handleEdit(record)"
            :disabled="isDisabledAuth('erpCompanyEmployeePostDetail:edit')"
          />
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="delete"
              :disabled="isDisabledAuth('erpCompanyEmployeePostDetail:delete')"/>
          </a-popconfirm>
        </span>

      </a-table>
    </div>
    <ErpEmployeePostDetailListModal ref="modalForm" @ok="modalFormOk"></ErpEmployeePostDetailListModal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction } from '@/api/manage'
  import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import JSearchSelect from '@/views/scy/components/JSearchSelect.vue'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput';
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import ErpEmployeePostDetailListModal from './modules/ErpEmployeePostDetailListModal'
  export default {
    name: 'ErpEmployeePostDetailList',
    mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    props: {
      detail: {
        type: Object,
        default: () => { return {} }
      },
      postCode: {
        type: String,
        default: ''
      }
    },
    components: {
      SelectUserByDep,
      JSearchSelect,
      SelectTeamInput,
      SelectCompanyInput,
      ErpEmployeePostDetailListModal
    },
    watch: {
			postCode: {
				handler (val) {
					if (val) {
            this.postCode = val
            this.loadData(1)
          }
				},
				immediate: true
			}
		},
    data () {
      return {
        description: '公司员工岗位明细表管理页面',
        // 表头
        columns: [],
        // 列设置
        settingColumns: [],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '岗位名称',
            align: 'center',
            dataIndex: 'postCode_dictText'
          },
          {
            title: '员工',
            align: 'center',
            dataIndex: 'employeeId_dictText'
          },
          {
            title: '公司',
            align: 'center',
            dataIndex: 'companyId_dictText'
          },
          {
            title: '团队',
            align: 'center',
            dataIndex: 'teamId_dictText'
          },
          {
            title: '部门',
            align: 'center',
            dataIndex: 'departId_dictText'
          },
          {
            title: '岗位序列',
            align: 'center',
            dataIndex: 'positionCategory_dictText'
          },
          {
            title: '职务级别',
            align: 'center',
            dataIndex: 'positionLevelId_dictText'
          },
          {
            title: '是否虚拟岗位',
            align: 'center',
            dataIndex: 'isVirtual_dictText'
          },
          {
            title: '任职时间',
            align: 'center',
            dataIndex: 'workingTime'
          },
          {
            title: '备注',
            align: 'center',
            dataIndex: 'remark'
          },
          {
            title: '数据来源',
            align: 'center',
            dataIndex: 'postDataSource_dictText'
          },
          // {
          //   title: '最后维护时间',
          //   align: 'center',
          //   dataIndex: 'createTime',
          //   customRender: function (t, r, index) {
          //     return r.updateTime != null ? r.updateTime : r.createTime;
          //   }
          // },
          // {
          //   title: '最后维护人',
          //   align: 'center',
          //   dataIndex: 'createBy_dictText',
          //   customRender: function (t, r, index) {
          //     return r.updateBy_dictText != null ? r.updateBy_dictText : r.createBy_dictText;
          //   }
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 160,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: '/api/erp/files/employee/erpEmployeePostChangeRecord/list',
          delete: '/api/erp/files/employee/erpEmployeePostChangeRecord/delete',
          deleteBatch: '/api/erp/files/employee/erpEmployeePostChangeRecord/deleteBatch',
          exportXlsUrl: '/api/erp/files/employee/erpEmployeePostChangeRecord/exportXls',
          importExcelUrl: '/api/erp/files/employee/erpEmployeePostChangeRecord/importExcel'
        },
        dictOptions: {},
        superFieldList: [],
        disableMixinCreated: true
      }
    },
    created() {
      this.initDictConfig()
      this.initColumns()
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        // 加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1
        }
        var params = this.getQueryParams() // 查询条件
        params.pageUrl = this.$route.path
        this.loading = true
        if (!this.postCode) {
          this.loading = false
          return;
        }
        params.postCode = this.postCode
        params.isDuty = '1'
        getAction(this.url.list, params).then(res => {
          if (res.success) {
            // update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
            // 判断是否当前页没有数据且不为第一页
            if (this.dataSource.length == 0 && this.ipagination.current != 1) {
              this.ipagination.current = this.ipagination.current - 1
              this.loadData(this.ipagination.current - 1);
            }
            // update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.dataSource = [];
            this.ipagination.total = 0
            this.$message.warning(res.message)
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false
        }).catch(err => {
          this.$message.warning(err.message)
        })
      },
      handleEdit: function (record) {
        this.$refs.modalForm.edit(record, this.detail)
        this.$refs.modalForm.title = '编辑'
        this.$refs.modalForm.disableSubmit = false
      },
      handleAdd: function () {
        this.$refs.modalForm.add(this.detail)
        this.$refs.modalForm.title = '新增'
        this.$refs.modalForm.disableSubmit = false
      },
      initDictConfig() {
      },
      getSuperFieldList() {
        let fieldList = [];
        fieldList.push({ type: 'string', value: 'companyId', text: '公司id', dictCode: '' })
        fieldList.push({ type: 'string', value: 'employeeId', text: '员工id', dictCode: '' })
        fieldList.push({ type: 'string', value: 'postCode', text: '岗位', dictCode: '' })
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
